473,418 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

single checkbox enable/disable dropdown

I've been looking all over and I can't seem to find what ought to be
simple.

I need to disable a drop down when a checkbox is checked, and enable it
when same checkbox is unchecked.

I've found any number of scripts to disable / enable a drop down but they
are all made to work with 2 different buttons, radio group selections, etc.
I can't seem to come up with one that can toggle off a single checkbox.

help please.

Thanks
Nov 8 '06 #1
2 26295
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Untitled Document</title>
<script type="text/javascript">

window.onload = function() {
document.getElementById('demo').disabled =
document.getElementById('demo_control1').checked;
}

</script>
</head>

<body>

<div id="container">

<select name="demo" id="demo">
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>
<option value="Option 4">Option 4</option>
<option value="Option 5">Option 5</option>
</select>

<label><input type="checkbox" name="demo_control1" id="demo_control1"
onchange="document.getElementById('demo').disabled = this.checked;" />
Activate/Deactivate Selectbox</label>

</div>

</body>
</html>

Kevin wrote:
I've been looking all over and I can't seem to find what ought to be
simple.

I need to disable a drop down when a checkbox is checked, and enable it
when same checkbox is unchecked.

I've found any number of scripts to disable / enable a drop down but they
are all made to work with 2 different buttons, radio group selections, etc.
I can't seem to come up with one that can toggle off a single checkbox.

help please.

Thanks
Nov 8 '06 #2
i would make something more comprehensive to "normal" person :)

something like:

function foo(){
if (document.formname.checkboxname.checked) {
document.formname.dropdownlistname.disabled=true;
}else{
document.formname.dropdownlistname.disabled=false;
}

}

Here ur form tag
..
..
..
<input type="checkbox" name="checkboxname" value="something"
onclick="foo()">
..
..
..
Close form.
neogeek wrote:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Untitled Document</title>
<script type="text/javascript">

window.onload = function() {
document.getElementById('demo').disabled =
document.getElementById('demo_control1').checked;
}

</script>
</head>

<body>

<div id="container">

<select name="demo" id="demo">
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>
<option value="Option 4">Option 4</option>
<option value="Option 5">Option 5</option>
</select>

<label><input type="checkbox" name="demo_control1" id="demo_control1"
onchange="document.getElementById('demo').disabled = this.checked;" />
Activate/Deactivate Selectbox</label>

</div>

</body>
</html>

Kevin wrote:
I've been looking all over and I can't seem to find what ought to be
simple.

I need to disable a drop down when a checkbox is checked, and enable it
when same checkbox is unchecked.

I've found any number of scripts to disable / enable a drop down but they
are all made to work with 2 different buttons, radio group selections, etc.
I can't seem to come up with one that can toggle off a single checkbox.

help please.

Thanks
Nov 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: HolaGoogle | last post by:
Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field...
2
by: HolaGoogle | last post by:
Can you please tell me the right way to do this?? it's realy important! thanks in advance... Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have...
3
by: Bob Bedford | last post by:
I've this code: function checkdate(FormSubmit){ alert(document.getElementById('Mois').value); if(eval(document.getElementById('Mois'))>0 && eval(document.getElementById('Annee'))>0){...
3
by: Alphonse Giambrone | last post by:
I am trying to enable/disable a requiredfieldvalidator on the client side and am generating an error. I had found some documentation on validation which states that I should be able to...
1
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
8
by: John | last post by:
Hello. I have a search form for music albums which among other things I need to search all the song titles of the song. Normally in a search form I would have checkboxes the user can use to...
2
by: RootSpy2006 | last post by:
Hi All, Problem Definition: --------------------- Microsoft Wirelss Keyboard works in BIOS but does not work when booting into windows. Discovered Work-around: -----------------------------...
2
by: Naushad | last post by:
Hi all, I am using the countinous form. I want to Enable/Disable the some fields for perticular records as per the following condition when open the form. I have written this code in "On Current...
3
by: sanndeb | last post by:
I want to enable/disable controls of a asp.net page against a logged in user's permission. say 'admin' & 'hr' can change user's birth date text-box in a page but others will see the text-box as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.